package sg.edu.nus.iss.pacman.net.webservice;

import javax.xml.rpc.JAXRPCException;
import javax.xml.namespace.QName;
import javax.microedition.xml.rpc.Operation;
import javax.microedition.xml.rpc.Type;
import javax.microedition.xml.rpc.ComplexType;
import javax.microedition.xml.rpc.Element;

public class PacManWebServiceService_Stub implements PacManWebServiceService, javax.xml.rpc.Stub
{
    private String[] _propertyNames;
    private Object[] _propertyValues;

    public PacManWebServiceService_Stub()
    {
        _propertyNames = new String[]
            {
                ENDPOINT_ADDRESS_PROPERTY
            };
        _propertyValues = new Object[]
            {
                "http://localhost:8080/PacManServer/PacManWebServiceService"
            };
    }

    public PacManWebServiceService_Stub(String endpoint)
    {
        _propertyNames = new String[]
            {
                ENDPOINT_ADDRESS_PROPERTY
            };
        _propertyValues = new Object[]
            {
                endpoint
            };
    }

    public void _setProperty(String name, Object value)
    {
        int size = _propertyNames.length;
        for (int i = 0; i < size; ++i)
        {
            if (_propertyNames[i].equals(name))
            {
                _propertyValues[i] = value;
                return;
            }
        }
        String[] newPropNames = new String[size + 1];
        System.arraycopy(_propertyNames, 0, newPropNames, 0, size);
        _propertyNames = newPropNames;
        Object[] newPropValues = new Object[size + 1];
        System.arraycopy(_propertyValues, 0, newPropValues, 0, size);
        _propertyValues = newPropValues;

        _propertyNames[size] = name;
        _propertyValues[size] = value;
    }

    public Object _getProperty(String name)
    {
        for (int i = 0; i < _propertyNames.length; ++i)
        {
            if (_propertyNames[i].equals(name))
            {
                return _propertyValues[i];
            }
        }
        if (ENDPOINT_ADDRESS_PROPERTY.equals(name) || USERNAME_PROPERTY.equals(name) || PASSWORD_PROPERTY.equals(name))
        {
            return null;
        }
        if (SESSION_MAINTAIN_PROPERTY.equals(name))
        {
            return new Boolean(false);
        }
        throw new JAXRPCException("Stub does not recognize property: " + name);
    }

    protected void _prepOperation(Operation op)
    {
        for (int i = 0; i < _propertyNames.length; ++i)
        {
            op.setProperty(_propertyNames[i], _propertyValues[i].toString());
        }
    }

    public void addUserProfile(userProfile userProfile) throws java.rmi.RemoteException
    {
        Object inputObject[] = new Object[]
        {
            userProfile_toObject(userProfile)
        };

        Operation op = Operation.newInstance(_qname_operation_addUserProfile, _type_addUserProfile, _type_addUserProfileResponse);
        _prepOperation(op);
        op.setProperty(Operation.SOAPACTION_URI_PROPERTY, "");
        Object resultObj;
        try
        {
            resultObj = op.invoke(inputObject);
        }
        catch (JAXRPCException e)
        {
            Throwable cause = e.getLinkedCause();
            if (cause instanceof java.rmi.RemoteException)
            {
                throw (java.rmi.RemoteException) cause;
            }
            throw e;
        }

    }

    public String[] getMapListing() throws java.rmi.RemoteException
    {
        Object inputObject[] = new Object[]
        {
        };

        Operation op = Operation.newInstance(_qname_operation_getMapListing, _type_getMapListing, _type_getMapListingResponse);
        _prepOperation(op);
        op.setProperty(Operation.SOAPACTION_URI_PROPERTY, "");
        Object resultObj;
        try
        {
            resultObj = op.invoke(inputObject);
        }
        catch (JAXRPCException e)
        {
            Throwable cause = e.getLinkedCause();
            if (cause instanceof java.rmi.RemoteException)
            {
                throw (java.rmi.RemoteException) cause;
            }
            throw e;
        }

        String[] _res = new String[((Object[]) ((Object[]) resultObj)[0]).length];
        System.arraycopy(((Object[]) resultObj)[0], 0, _res, 0, _res.length);
        return _res;
    }

    private static Object userProfile_toObject(userProfile obj)
    {
        if (obj == null)
        {
            return null;
        }
        Object result[] = new Object[5];
        result[0] = obj.getDob();
        result[1] = obj.getEmail();
        result[2] = new Integer(obj.getGender());
        result[3] = obj.getName();
        result[4] = score_ArraytoObject(obj.getScores());
        return result;
    }

    private static Object score_ArraytoObject(score[] obj)
    {
        if (obj == null)
        {
            return null;
        }
        Object result[] = new Object[obj.length];
        for (int i = 0; i < obj.length; i++)
        {
            Object[] resultArray = new Object[2];
            resultArray[0] = obj[i].getMapName();
            resultArray[1] = new Integer(obj[i].getScore());
            result[i] = resultArray;
        }
        return result;
    }
    protected static final QName _qname_operation_addUserProfile = new QName("http://webservice.pacman.iss.nus.edu.sg/", "addUserProfile");
    protected static final QName _qname_operation_getMapListing = new QName("http://webservice.pacman.iss.nus.edu.sg/", "getMapListing");
    protected static final QName _qname_addUserProfile = new QName("http://webservice.pacman.iss.nus.edu.sg/", "addUserProfile");
    protected static final QName _qname_getMapListingResponse = new QName("http://webservice.pacman.iss.nus.edu.sg/", "getMapListingResponse");
    protected static final QName _qname_getMapListing = new QName("http://webservice.pacman.iss.nus.edu.sg/", "getMapListing");
    protected static final QName _qname_addUserProfileResponse = new QName("http://webservice.pacman.iss.nus.edu.sg/", "addUserProfileResponse");
    protected static final Element _type_getMapListingResponse;
    protected static final Element _type_getMapListing;
    protected static final Element _type_addUserProfileResponse;
    protected static final Element _type_addUserProfile;

    static
    {
        _type_getMapListingResponse = new Element(_qname_getMapListingResponse, _complexType(new Element[]
            {
                new Element(new QName("", "return"), Type.STRING, 0, Element.UNBOUNDED, true)
            }), 1, 1, false);
        _type_addUserProfile = new Element(_qname_addUserProfile, _complexType(new Element[]
            {
                new Element(new QName("", "userProfile"), _complexType(new Element[]
                {
                    new Element(new QName("", "dob"), Type.STRING, 0, 1, false),
                    new Element(new QName("", "email"), Type.STRING, 0, 1, false),
                    new Element(new QName("", "gender"), Type.INT),
                    new Element(new QName("", "name"), Type.STRING, 0, 1, false),
                    new Element(new QName("", "scores"), _complexType(new Element[]
                    {
                        new Element(new QName("", "mapName"), Type.STRING, 0, 1, false),
                        new Element(new QName("", "score"), Type.INT)
                    }), 0, Element.UNBOUNDED, true)
                }))
            }), 1, 1, false);
        _type_getMapListing = new Element(_qname_getMapListing, _complexType(new Element[]
            {
            }), 1, 1, false);
        _type_addUserProfileResponse = new Element(_qname_addUserProfileResponse, _complexType(new Element[]
            {
            }), 1, 1, false);
    }

    private static ComplexType _complexType(Element[] elements)
    {
        ComplexType result = new ComplexType();
        result.elements = elements;
        return result;
    }
}
